package com.cqie.practicaltraining.config.exception.exception.handler;

import com.cqie.practicaltraining.config.exception.exception.annotation.GlobalException;
import com.cqie.practicaltraining.config.exception.exception.exception.IGlobalException;
import com.cqie.practicaltraining.config.result.R;
import com.cqie.practicaltraining.config.result.ResultCodeEnum;
import com.fasterxml.jackson.databind.JsonMappingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * JSON映射异常
 * JsonMappingException：通常表示json格式错误
 *
 * @author shineTan
 * @date 2022/12/26 14:23
 */
@GlobalException(throwable = JsonMappingException.class)
public class JsonMappingExceptionHandler implements IGlobalException<R, JsonMappingException> {

    @Override
    public R exception(JsonMappingException throwable, HttpServletRequest request, HttpServletResponse response) {
        return R.Failed(ResultCodeEnum.REQUEST_PARAM_ERROR.getCode(), String.format("请求参数JSON格式错误"));
    }
}
